<?php
namespace app\common\logic;

use app\common\model\Sms as Sms;
class SmsLogic {
    public function addSms($data) {
        $sms = new Sms;
        
        $data['created_at'] = date('Y-m-d H:i:s',time());
        $data['updated_at'] = date('Y-m-d H:i:s',time());
        
        $sms->data($data);
        if($sms->allowField(true)->save()) {
            return $sms;
        }
        
        return NULL;
    }
    
    public function checkSmsHas($uid, $shortcode) {
        $sms = new Sms;
        $result = $sms->where('user_id', $uid)
             ->where('shortcode',$shortcode)
             ->find();
        return $result;
    }
    
    public function delHasSms($id) {
        $sms = Sms::get($id);
        return $sms->delete();
    }
}
